/* GUI CONVERTED from rqlmt.p (converter v1.75) Sat Aug 12 23:12:33 2000 */
/* rqlmt.p - Level Table Maintenance                                        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                       */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                     */
/* REVISION 8.5       LAST MODIFIED: 05/09/97  BY: *J1Q2* Patrick Rowan     */


/*!
 ----------------------------------------------------------------------------
 DESCRIPTION: ADDS/MODS/DELETES requisition approval/review levels.
              Supports the multi-line Purchase Requisition Module of MFG/PRO.

 Notes:
 1) The level table represents a true scale.  Entries are validated to
    ensure the fit within the range.  To do this validation, the level amount
    entered is validated against level amounts of the codes directly
    greater than AND less than the code entered on the screen.
 2) The delete rule checks if the level is currently associated with any
    approver and denies the delete request if the level is found in the
    approver table.
 ============================================================================
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan       */
/* REVISION: 8.5      LAST MODIFIED: 07/23/98   BY: *J2TL* Patrick Rowan    */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb                */
 !*/

          /* DISPLAY TITLE  */
          {mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rqlmt_p_1 "Approval Amount"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

          /* VARIABLES  */
          define variable min_amt   like rql_amt no-undo.
          define variable max_amt   like rql_amt no-undo.
          define variable amount    like rql_amt no-undo.
/*J2TL*/  define variable min_disp  as character no-undo.
/*J2TL*/  define variable max_disp  as character no-undo.

          /* LOGICALS  */
          define variable del-yn    like mfc_logical no-undo
                    initial no.
          define variable msg as character format "X(70)".

          /* FRAME A: SELECTION FORM   */

          
/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
             
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
rql_level          colon 25
             skip(1)
             rql_desc           colon 25
             rql_amt            colon 25  label {&rqlmt_p_1}
             rqf_appr_curr      colon 25
              SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



             /* SET EXTERNAL LABELS */
             setFrameLabels(frame a:handle).

          /* DISPLAY   */
          view frame a.

          /* RETRIEVE CONTROL RECORD   */
          {gprun.i ""rqpma.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

          find first rqf_ctrl no-lock no-error.

          mainloop:
          repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


             /* PROMPT-FOR KEYS   */

             prompt-for
                rql_level
                with frame a editing:

                /* FIND NEXT/PREVIOUS RECORD */
                {mfnp.i rql_mstr rql_level rql_level rql_level
                        rql_level rql_lev}
                if recno <> ? then do:
                    display
                       rql_level
                       rql_amt
                       rqf_appr_curr
                       rql_desc
                       with frame a.
                end.  /* if recno <> ? */

             end.  /* prompt-for */

/*J2TL*/
/*J2TL*/     /*  EDIT  */
/*J2TL*/     if input rql_level = "" then do:
/*J2TL*/        {mfmsg.i 40 3}
/*J2TL*/        /* BLANK NOT ALLOWED  */
/*J2TL*/        undo, retry.
/*J2TL*/     end.
/*J2TL*/
/*J2TL*/     if input rql_level = 0 then do:
/*J2TL*/
/*J2TL*/        /*  ONE TIME CODE TO FIND THE "00" LEVEL AND DELETE  */
/*J2TL*/        /*  IF IT EXISTS.  ELSE, DON'T ALLOW ENTRY OF "00"   */
/*J2TL*/
/*J2TL*/        for first rql_mstr where
/*J2TL*/            rql_level = input rql_level exclusive-lock.
/*J2TL*/        end.
/*J2TL*/
/*J2TL*/        if available rql_mstr then do:
/*J2TL*/            /* OK TO DELETE */
/*J2TL*/            delete rql_mstr.
/*J2TL*/            {mfmsg.i 22 1}      /* RECORD DELETED */
/*J2TL*/            {mfmsg.i 3953 3}
/*J2TL*/            /* VALUE MUST BE GREATER THAN ZERO  */
/*J2TL*/            next mainloop.
/*J2TL*/        end.
/*J2TL*/        else do:
/*J2TL*/            {mfmsg.i 3953 3}
/*J2TL*/            /* VALUE MUST BE GREATER THAN ZERO  */
/*J2TL*/            undo, retry.
/*J2TL*/        end.
/*J2TL*/     end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* if input rql_level = 0 */
/*J2TL*/

             /*  ADD/MODIFY/DELETE  */

             find rql_mstr where
                rql_level = input rql_level no-error.
             if not available rql_mstr then do:

                {mfmsg.i 1 1}   /* ADDING NEW RECORD  */
                create rql_mstr.
                assign
                   rql_level = input rql_level.
                if recid(rql_mstr) = -1 then .

             end.  /* if not available rql_mstr */

             display
                rql_amt
                rqf_appr_curr
                rql_desc
                with frame a.

             ststatus = stline[2].
             status input ststatus.
             del-yn = no.

             setloop1:
             do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

                set
                   rql_desc
                   rql_amt
                   go-on("F5" "CTRL-D")
                   with frame a.

                /*  DELETE  */
                if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
                then do:
                    /* CHECK FOR ACTIVE APPROVERS WITH THIS APPROVAL CODE  */
                    /* ACTIVE APPROVERS HAVE END EFFECTIVITY AFTER TODAY
                       OR HAVE NO END EFFECTIVITY. */
                    find first rqa_mstr where
                        (rqa_rvw_level = rql_level or
                         rqa_apr_level = rql_level) and
                        (rqa_end > today or rqa_end = ?)
                        no-lock no-error.
                    if available rqa_mstr then do:
                        {mfmsg.i 1787 4}
                        /* CANNOT DELETE - APPR DETAIL RECORDS EXIST  */
                        undo, leave setloop1.
                    end.

                    del-yn = yes.
                    {mfmsg01.i 11 1 del-yn}  /* CONFIRM DELETE */
                    if del-yn = no then undo setloop1.
                end.

                if del-yn then do:
                    /* OK TO DELETE */
                    delete rql_mstr.
                    clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
                    del-yn = no.
                    next mainloop.
                end.

                /*  VALIDATE LEVEL & AMOUNT  */
                min_amt = 0.
                amount = input rql_amt.

                /*  LOCATE PRIOR LEVEL  */
                find last rql_mstr where
                   rql_level < input rql_level
                   no-lock no-error.
                if available rql_mstr then
                    min_amt = rql_amt.
                else
                    min_amt = 0.

                /*  LOCATE NEXT LEVEL  */
                find first rql_mstr where
                   rql_level > input rql_level
                   no-lock no-error.
                if available rql_mstr then
                    max_amt = rql_amt.
                else
/*J2TL*             max_amt = 999999999999.99   .   */
/*J2TL*/            max_amt = 999999999999   .

                if (input rql_level = 00 and amount = min_amt) or
                   (input rql_level = 99 and amount = max_amt)
                   then .  /* OK, adding min or max record */
                else do:
                   if amount <= min_amt or amount >= max_amt
                      then do:
                      /*   {mfmsg.i 1786 3}    */
/*J2TL*                  msg =
 *                       left-trim(string(min_amt,"ZZZ,ZZZ,ZZZ,ZZ9")) + " " +
 *                       left-trim(string(max_amt,"ZZZ,ZZZ,ZZZ,ZZ9")).
 *                       {mfmsg02.i 1786 4 msg}
 *                    /*  message msg.         */
 *J2TL*/
/*J2TL*/                 assign
/*J2TL*/                    min_disp =
/*J2TL*/                        left-trim(string(min_amt,"ZZZ,ZZZ,ZZZ,ZZ9"))
/*J2TL*/                    max_disp =
/*J2TL*/                        left-trim(string(max_amt,"ZZZ,ZZZ,ZZZ,ZZ9")).
/*J2TL*/                 {mfmsg03.i 1786 4 min_disp max_disp """" }
/*J2TL*/                 /*APPROVAL AMOUNT FOR THIS LEVEL MUST BE BETWEEN ...*/
                         next-prompt rql_amt.
                         undo setloop1.
                    end.
                 end.  /* if (level = '00' and amount = min_amt) */

             end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* setloop1  */

        end.  /* mainloop repeat  */

        status input.
